﻿using System;
using System.Collections.Generic;
using IllusionUtility.GetUtility;
using UnityEngine;

// Token: 0x0200060B RID: 1547
public class AssignedAnotherWeights
{
	// Token: 0x0600250A RID: 9482 RVA: 0x00143400 File Offset: 0x00141600
	public AssignedAnotherWeights()
	{
		this.dictBone = new Dictionary<string, GameObject>();
	}

	// Token: 0x17000400 RID: 1024
	// (get) Token: 0x0600250B RID: 9483 RVA: 0x00143414 File Offset: 0x00141614
	// (set) Token: 0x0600250C RID: 9484 RVA: 0x0014341C File Offset: 0x0014161C
	public Dictionary<string, GameObject> dictBone { get; private set; }

	// Token: 0x0600250D RID: 9485 RVA: 0x00143428 File Offset: 0x00141628
	public virtual void Release()
	{
		this.dictBone.Clear();
	}

	// Token: 0x0600250E RID: 9486 RVA: 0x00143438 File Offset: 0x00141638
	public virtual void CreateBoneList(GameObject obj, string name)
	{
		this.dictBone.Clear();
		this.CreateBoneListLoop(obj, name);
	}

	// Token: 0x0600250F RID: 9487 RVA: 0x00143450 File Offset: 0x00141650
	public virtual void CreateBoneListLoop(GameObject obj, string name)
	{
		if ((string.Compare(obj.name, 0, name, 0, name.Length) == 0 || string.Empty == name) && !this.dictBone.ContainsKey(obj.name))
		{
			this.dictBone[obj.name] = obj;
		}
		for (int i = 0; i < obj.transform.childCount; i++)
		{
			this.CreateBoneListLoop(obj.transform.GetChild(i).gameObject, name);
		}
	}

	// Token: 0x06002510 RID: 9488 RVA: 0x001434E4 File Offset: 0x001416E4
	public virtual void CreateBoneList(GameObject obj, string assetBundleName, string assetName)
	{
		this.dictBone.Clear();
		if (!global::AssetBundleCheck.IsFile(assetBundleName, assetName))
		{
			string message = "読み込みエラー\r\nassetBundleName：" + assetBundleName + "\tassetName：" + assetName;
			global::Debug.LogWarning(message);
			return;
		}
		global::AssetBundleLoadAssetOperation assetBundleLoadAssetOperation = global::AssetBundleManager.LoadAsset(assetBundleName, assetName, typeof(TextAsset), null);
		if (assetBundleLoadAssetOperation.IsEmpty())
		{
			string message2 = "読み込みエラー\r\nassetName：" + assetName;
			global::Debug.LogError(message2);
			return;
		}
		TextAsset asset = assetBundleLoadAssetOperation.GetAsset<TextAsset>();
		string[,] array;
		global::YS_Assist.GetListString(asset.text, out array);
		int length = array.GetLength(0);
		int length2 = array.GetLength(1);
		if (length != 0 && length2 != 0)
		{
			for (int i = 0; i < length; i++)
			{
				GameObject gameObject = obj.transform.FindLoop(array[i, 0]);
				if (gameObject)
				{
					this.dictBone[array[i, 0]] = gameObject;
				}
			}
		}
		global::AssetBundleManager.UnloadAssetBundle(assetBundleName, true, null);
	}

	// Token: 0x06002511 RID: 9489 RVA: 0x001435E4 File Offset: 0x001417E4
	public virtual void CreateBoneList(GameObject obj, string[] bonename)
	{
		this.dictBone.Clear();
		for (int i = 0; i < bonename.Length; i++)
		{
			GameObject gameObject = obj.transform.FindLoop(bonename[i]);
			if (gameObject)
			{
				this.dictBone[bonename[i]] = gameObject;
			}
		}
	}

	// Token: 0x06002512 RID: 9490 RVA: 0x0014363C File Offset: 0x0014183C
	public virtual void AssignedWeights(GameObject obj, string delTopName, Transform rootBone = null)
	{
		if (this.dictBone == null || this.dictBone.Count == 0)
		{
			return;
		}
		if (null == obj)
		{
			return;
		}
		this.AssignedWeightsLoop(obj.transform, rootBone);
		GameObject gameObject = obj.transform.FindLoop(delTopName);
		if (gameObject)
		{
			gameObject.transform.SetParent(null);
			UnityEngine.Object.Destroy(gameObject);
		}
	}

	// Token: 0x06002513 RID: 9491 RVA: 0x001436AC File Offset: 0x001418AC
	public virtual void AssignedWeightsLoop(Transform t, Transform rootBone = null)
	{
		SkinnedMeshRenderer component = t.GetComponent<SkinnedMeshRenderer>();
		if (component)
		{
			int num = component.bones.Length;
			Transform[] array = new Transform[num];
			GameObject gameObject = null;
			for (int i = 0; i < num; i++)
			{
				if (this.dictBone.TryGetValue(component.bones[i].name, out gameObject))
				{
					array[i] = gameObject.transform;
				}
			}
			component.bones = array;
			if (rootBone)
			{
				component.rootBone = rootBone;
			}
			else if (component.rootBone && this.dictBone.TryGetValue(component.rootBone.name, out gameObject))
			{
				component.rootBone = gameObject.transform;
			}
		}
		foreach (object obj in t.gameObject.transform)
		{
			Transform t2 = (Transform)obj;
			this.AssignedWeightsLoop(t2, rootBone);
		}
	}
}
